package com.cloudfun.campusshare.controller.miniprogram;

import com.cloudfun.campusshare.common.constant.Code;
import com.cloudfun.campusshare.common.response.BaseResult;
import com.cloudfun.campusshare.common.response.BaseResultFactory;
import com.cloudfun.campusshare.configuration.config.WxConfig;
import com.cloudfun.campusshare.service.WeChatService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RestController
@RequestMapping("v1/wx")
public class WxController {

    @Autowired
    private WxConfig wxConfig;

    @Autowired
    private WeChatService weChatService;

    @GetMapping("page/sign")
    @ApiOperation(value = "JSSDK 签名", notes = "JSSDK 签名")
    public BaseResult<Map<String, Object>> pageSign(String url){
        String accessToken = wxConfig.accessToken();
        String ticket = wxConfig.ticket(accessToken);
        Map<String, Object> sign = wxConfig.sign(url, ticket);
        return  BaseResultFactory.produceResult(Code.SUCCESS, sign);
    }
}
